<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Free Software" and "Free Software Needs
Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
and with the Back-Cover Texts as in (a) below.

(a) The FSF's Back-Cover Text is: "You are free to copy and modify
this GNU Manual.  Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom." -->
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Debugging with GDB: Blocks In Guile</title>

<meta name="description" content="Debugging with GDB: Blocks In Guile">
<meta name="keywords" content="Debugging with GDB: Blocks In Guile">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Guile-API.html#Guile-API" rel="up" title="Guile API">
<link href="Symbols-In-Guile.html#Symbols-In-Guile" rel="next" title="Symbols In Guile">
<link href="Frames-In-Guile.html#Frames-In-Guile" rel="prev" title="Frames In Guile">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Blocks-In-Guile"></a>
<div class="header">
<p>
Next: <a href="Symbols-In-Guile.html#Symbols-In-Guile" accesskey="n" rel="next">Symbols In Guile</a>, Previous: <a href="Frames-In-Guile.html#Frames-In-Guile" accesskey="p" rel="prev">Frames In Guile</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Accessing-blocks-from-Guile_002e"></a>
<h4 class="subsubsection">23.3.3.16 Accessing blocks from Guile.</h4>

<a name="index-blocks-in-guile"></a>
<a name="index-_003cgdb_003ablock_003e"></a>

<p>In <small>GDB</small>, symbols are stored in blocks.  A block corresponds
roughly to a scope in the source code.  Blocks are organized
hierarchically, and are represented individually in Guile as an object
of type <code>&lt;gdb:block&gt;</code>.  Blocks rely on debugging information being
available.
</p>
<p>A frame has a block.  Please see <a href="Frames-In-Guile.html#Frames-In-Guile">Frames In Guile</a>, for a more
in-depth discussion of frames.
</p>
<p>The outermost block is known as the <em>global block</em>.  The global
block typically holds public global variables and functions.
</p>
<p>The block nested just inside the global block is the <em>static
block</em>.  The static block typically holds file-scoped variables and
functions.
</p>
<p><small>GDB</small> provides a method to get a block&rsquo;s superblock, but there
is currently no way to examine the sub-blocks of a block, or to
iterate over all the blocks in a symbol table (see <a href="Symbol-Tables-In-Guile.html#Symbol-Tables-In-Guile">Symbol Tables In Guile</a>).
</p>
<p>Here is a short example that should help explain blocks:
</p>
<div class="smallexample">
<pre class="smallexample">/* This is in the global block.  */
int global;

/* This is in the static block.  */
static int file_scope;

/* 'function' is in the global block, and 'argument' is
   in a block nested inside of 'function'.  */
int function (int argument)
{
  /* 'local' is in a block inside 'function'.  It may or may
     not be in the same block as 'argument'.  */
  int local;

  {
     /* 'inner' is in a block whose superblock is the one holding
        'local'.  */
     int inner;

     /* If this call is expanded by the compiler, you may see
        a nested block here whose function is 'inline_function'
        and whose superblock is the one holding 'inner'.  */
     inline_function ();
  }
}
</pre></div>

<p>The following block-related procedures are provided by the
<code>(gdb)</code> module:
</p>
<dl>
<dt><a name="index-block_003f"></a>Scheme Procedure: <strong>block?</strong> <em>object</em></dt>
<dd><p>Return <code>#t</code> if <var>object</var> is a <code>&lt;gdb:block&gt;</code> object.
Otherwise return <code>#f</code>.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dvalid_003f"></a>Scheme Procedure: <strong>block-valid?</strong> <em>block</em></dt>
<dd><p>Returns <code>#t</code> if <code>&lt;gdb:block&gt;</code> <var>block</var> is valid,
<code>#f</code> if not.  A block object can become invalid if the block it
refers to doesn&rsquo;t exist anymore in the inferior.  All other
<code>&lt;gdb:block&gt;</code> methods will throw an exception if it is invalid at
the time the procedure is called.  The block&rsquo;s validity is also checked
during iteration over symbols of the block.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dstart"></a>Scheme Procedure: <strong>block-start</strong> <em>block</em></dt>
<dd><p>Return the start address of <code>&lt;gdb:block&gt;</code> <var>block</var>.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dend"></a>Scheme Procedure: <strong>block-end</strong> <em>block</em></dt>
<dd><p>Return the end address of <code>&lt;gdb:block&gt;</code> <var>block</var>.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dfunction"></a>Scheme Procedure: <strong>block-function</strong> <em>block</em></dt>
<dd><p>Return the name of <code>&lt;gdb:block&gt;</code> <var>block</var> represented as a
<code>&lt;gdb:symbol&gt;</code> object.
If the block is not named, then <code>#f</code> is returned.
</p>
<p>For ordinary function blocks, the superblock is the static block.
However, you should note that it is possible for a function block to
have a superblock that is not the static block &ndash; for instance this
happens for an inlined function.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dsuperblock"></a>Scheme Procedure: <strong>block-superblock</strong> <em>block</em></dt>
<dd><p>Return the block containing <code>&lt;gdb:block&gt;</code> <var>block</var>.
If the parent block does not exist, then <code>#f</code> is returned.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dglobal_002dblock"></a>Scheme Procedure: <strong>block-global-block</strong> <em>block</em></dt>
<dd><p>Return the global block associated with <code>&lt;gdb:block&gt;</code> <var>block</var>.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dstatic_002dblock"></a>Scheme Procedure: <strong>block-static-block</strong> <em>block</em></dt>
<dd><p>Return the static block associated with <code>&lt;gdb:block&gt;</code> <var>block</var>.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dglobal_003f"></a>Scheme Procedure: <strong>block-global?</strong> <em>block</em></dt>
<dd><p>Return <code>#t</code> if <code>&lt;gdb:block&gt;</code> <var>block</var> is a global block.
Otherwise return <code>#f</code>.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dstatic_003f"></a>Scheme Procedure: <strong>block-static?</strong> <em>block</em></dt>
<dd><p>Return <code>#t</code> if <code>&lt;gdb:block&gt;</code> <var>block</var> is a static block.
Otherwise return <code>#f</code>.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dsymbols"></a>Scheme Procedure: <strong>block-symbols</strong></dt>
<dd><p>Return a list of all symbols (as &lt;gdb:symbol&gt; objects) in
<code>&lt;gdb:block&gt;</code> <var>block</var>.
</p></dd></dl>

<dl>
<dt><a name="index-make_002dblock_002dsymbols_002diterator"></a>Scheme Procedure: <strong>make-block-symbols-iterator</strong> <em>block</em></dt>
<dd><p>Return an object of type <code>&lt;gdb:iterator&gt;</code> that will iterate
over all symbols of the block.
Guile programs should not assume that a specific block object will
always contain a given symbol, since changes in <small>GDB</small> features and
infrastructure may cause symbols move across blocks in a symbol table.
See <a href="Iterators-In-Guile.html#Iterators-In-Guile">Iterators In Guile</a>.
</p></dd></dl>

<dl>
<dt><a name="index-block_002dsymbols_002dprogress_003f"></a>Scheme Procedure: <strong>block-symbols-progress?</strong></dt>
<dd><p>Return #t if the object is a &lt;gdb:block-symbols-progress&gt; object.
This object would be obtained from the <code>progress</code> element of the
<code>&lt;gdb:iterator&gt;</code> object returned by <code>make-block-symbols-iterator</code>.
</p></dd></dl>

<dl>
<dt><a name="index-lookup_002dblock"></a>Scheme Procedure: <strong>lookup-block</strong> <em>pc</em></dt>
<dd><p>Return the innermost <code>&lt;gdb:block&gt;</code> containing the given <var>pc</var>
value.  If the block cannot be found for the <var>pc</var> value specified,
the function will return <code>#f</code>.
</p></dd></dl>

<hr>
<div class="header">
<p>
Next: <a href="Symbols-In-Guile.html#Symbols-In-Guile" accesskey="n" rel="next">Symbols In Guile</a>, Previous: <a href="Frames-In-Guile.html#Frames-In-Guile" accesskey="p" rel="prev">Frames In Guile</a>, Up: <a href="Guile-API.html#Guile-API" accesskey="u" rel="up">Guile API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
